package com.itheima.test3;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main(String[] args) throws IOException {
        List<Student> stuList = new ArrayList<>();
        stuList.add(new Student("zhangsan", "nan", 20, 88));
        stuList.add(new Student("lisi", "nv", 19, 99));

        FileOutputStream fos = new FileOutputStream("student.txt");
        String start = "[";
        fos.write(start.getBytes());
        String split = ",\r\n";
        for (int i = 0; i < stuList.size(); i++) {
            Student stu = stuList.get(i);
            String str = "Student{name='" + stu.getName() + "', gender='" + stu.getSex() + "',age="
                    + stu.getAge() + ",score=" + stu.getScore() + "}";
            fos.write(str.getBytes());
            if (i != stuList.size() - 1) {
                fos.write(split.getBytes());
            }
        }
        String end = "]";
        fos.write(end.getBytes());

        fos.close();
    }
}
